package com.pro.service.imple;

import com.pro.mapper.JsUserOrderMapper;
import com.pro.pojo.JsUserOrder;
import com.pro.pojo.JsonData;
import com.pro.service.JsUserOrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李佳豪
 * @date 2022/1/6 19:26
 */
@Service
public class JsUserOrderServiceImple implements JsUserOrderService {
    @Autowired
    JsUserOrderMapper jsUserOrderMapper;

    @Override
    public Integer TotalCourseStatusCalculations(Integer orderType,Integer orderStatus){
        return jsUserOrderMapper.TotalCourseStatusCalculations(orderType,orderStatus);
    }

    @Override
    public Map<String,Object> UnsubscribeProcessingCount() {
        Map<String, Object> map = new HashMap<>();
       /* 退货中 OrderInReturn*/
        Integer OrderInReturn = jsUserOrderMapper.OrderInReturn();
        /*已退货 OrderReturned*/
        Integer OrderReturned = jsUserOrderMapper.OrderReturned();
        map.put("OrderInReturn",OrderInReturn);
        map.put("OrderReturned",OrderReturned);
        return map;
    }

    @Override
    public List<JsUserOrder> getAllCourseOrder(JsUserOrder param) {
        return jsUserOrderMapper.getAllCourseOrder(param);
    }

    @Override
    public List<JsUserOrder> QueryCourseOrdersByStatus(JsUserOrder param) {
        return jsUserOrderMapper.QueryCourseOrdersByStatus(param);
    }

    @Override
    public int DeleteOrderById(Integer orderId) {
        return jsUserOrderMapper.DeleteOrderById(orderId);
    }

    @Override
    public List<JsUserOrder> OrderAdvancedRetrieval(JsUserOrder param) {
        return jsUserOrderMapper.OrderAdvancedRetrieval(param);
    }

    @Override
    public Map<String,Object> CancelledOrder(JsUserOrder param) {
        Integer CancelTransactionCourse = 0;
        Integer CancelTransactionProduct = 0;
        List<JsUserOrder> jsUserOrders = jsUserOrderMapper.CancelledOrder(param);
        for (JsUserOrder jsUserOrder: jsUserOrders) {
            if (jsUserOrder.getOrderType() == 2){
                CancelTransactionCourse++;
            }else if(jsUserOrder.getOrderType() == 3){
                CancelTransactionProduct++;
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("CancelTransactionCourse",CancelTransactionCourse);
        map.put("CancelTransactionProduct",CancelTransactionProduct);
        return map;
    }

    @Override
    public List<JsUserOrder> GetAllAcceptedOrders(JsUserOrder param) {
        return jsUserOrderMapper.GetAllAcceptedOrders(param);
    }

    @Override
    public List<JsUserOrder> AcceptedOrdersAdvancedRetrieval(JsUserOrder param) {
        return jsUserOrderMapper.AcceptedOrdersAdvancedRetrieval(param);
    }

    @Override
    public Map<String, Object> AcceptedOrdersCount(JsUserOrder param) {
        Integer CourseAcceptedOrders = 0;
        Integer ProductAcceptedOrders = 0;

        List<JsUserOrder> jsUserOrders = jsUserOrderMapper.AcceptedOrdersCount(param);
        System.out.println(jsUserOrders);
        for (JsUserOrder jsUserOrder:jsUserOrders) {
            if (jsUserOrder.getOrderType() == 2){
                CourseAcceptedOrders++;
                continue;
            }else if(jsUserOrder.getOrderType() == 3){
                ProductAcceptedOrders++;
                continue;
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("CourseAcceptedOrders",CourseAcceptedOrders);
        map.put("ProductAcceptedOrders",ProductAcceptedOrders);
        return map;
    }
    /**
     * @author 李佳豪
     * @date 2022/1/12 18:46
     * 根据状态查询已受理订单信息
     */
    @Override
    public List<JsUserOrder> QueryAcceptedOrdersByType(JsUserOrder param) {
        return jsUserOrderMapper.QueryAcceptedOrdersByType(param);
    }
    /**
     * @Author 祖铭泽
     * @Date 2022/1/21/0013
     * @description 根据订单状态、订单类型查询订单数量
     */
    @Override
    public JsonData getReturnApplicationOrderCount(JsUserOrder jsUserOrder) {
        int returnApplicationOrderCount = jsUserOrderMapper.getReturnApplicationOrderCount(jsUserOrder);
        return returnApplicationOrderCount >= 0 ? JsonData.buildSuccess(returnApplicationOrderCount) : JsonData.buildError("获取失败");
    }


}
